//
//  ClienteViewController.m
//  InterventixApp
//
//  Created by Diego on 04/02/13.
//  Copyright (c) 2013 __MyCompanyName__. All rights reserved.
//

#import "ClienteViewController.h"
#import "Syncronize.h"

@implementation ClienteViewController

@synthesize table,search,clients;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    
    /*searchDisplayController.delegate = self;
    searchDisplayController.searchResultsDataSource = self;
    
     */
    self.search.delegate = self;
    self.table.tableHeaderView = search;
    
}

- (void)viewDidAppear:(BOOL)animated{
    //self.clients = [Syncronize findClientsLastUsed];
    //NSLog(@"size clients :%d",[self.clients count]);
    [self.table reloadData];
}




- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    int sections = 1;
    // Return the number of sections.
    return sections;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [clients count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    NSDictionary *cli = (NSDictionary *) [clients objectAtIndex:indexPath.row];
    
    
    
    cell.textLabel.text = [cli objectForKey:@"nominativo"];
    
    return cell;
}



- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    NSLog(@"search: %@",searchString);
    
   //self.clients = [Syncronize findClientsLike:searchString];
    
    return YES;
}
@end
